package com.tensquare.qa.controller;

import com.tensquare.qa.client.BaseClient;
import com.tensquare.qa.service.ProblemService;
import entity.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Date 2021/3/21 10:51
 */
@RestController
@CrossOrigin
@RequestMapping("/problem")
public class ProblemController {

    @Autowired
    private ProblemService problemService;

    @Autowired
    private BaseClient baseClient;


    /***
     * 跨域访问实现网络调用其他模块的方法
     * Param: [labelId]
     **/
    @GetMapping("/label/{labelId}")
    public Result findByLabelId(@PathVariable String labelId) {
        Result result = baseClient.findById(labelId);
        return result;
    }

    /***
     * 获取最新回答列表
     * Param: [label]
     **/
    @GetMapping("/newlist/{label}/{page}/{size}")
    public Result newList(@PathVariable String label, @PathVariable Integer page, @PathVariable Integer size) {
        return new Result(true, StatusCode.OK, "查询成功", problemService.newList(label,page,size));
    }

    /***
     * 获取热门回答列表
     * Param: [label]
     **/
    @GetMapping("/hotlist/{label}/{page}/{size}")
    public Result hotlist(@PathVariable String label, @PathVariable Integer page, @PathVariable Integer size) {
        return new Result(true, StatusCode.OK, "查询成功", problemService.hotlist(label,page,size));
    }

    /***
     * 获取等待回答列表
     * Param: [label]
     **/
    @GetMapping("/waitlist/{label}/{page}/{size}")
    public Result waitlist(@PathVariable String label, @PathVariable Integer page, @PathVariable Integer size) {
        return new Result(true, StatusCode.OK, "查询成功", problemService.waitlist(label,page,size));
    }
}
